package com.qf.service.impl;

import com.qf.dao.UsersDao;
import com.qf.entity.Users;
import com.qf.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class UsersServiceimpl implements UserService {

    @Resource
    private UsersDao usersDao;

    @Transactional
    public Users insertUsers(Users users) {
        return usersDao.save(users);
    }

    @Transactional
    public void deleteuserbyid(int userid) {
        usersDao.delete(userid);
    }

    public Users findByusernameAndPassword(String user, String pass) {
        return usersDao.findByusernameAndPassword(user,pass);
    }

    public List<Users> findByBirthdayBetween(String begin, String end) {
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

        try {
            Date begin1 = format.parse(begin);
            Date end1 = format.parse(end);
            return usersDao.findByBirthdayBetween(begin1,end1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }


}
